<?php //
class Api_Model_User
{
	private $user_id;
	private $username;
	private $fullname;
	private $dob;
	private $sex;
	private $address;
	private $email;
	private $phone;
	private $profile_picture;
	private $last_login;

	public function __construct($user_row = null) {
		if(!is_null($user_row) && $user_row instanceof Zend_Db_Table_Row) {
			$this->user_id = $user_row->user_id;
			$this->username = $user_row->username;
			$this->fullname = $user_row->fullname;
			$this->dob = $user_row->dob;
			$this->sex = $user_row->sex;
			$this->address = $user_row->address;
			$this->email = $user_row->email;
			$this->phone = $user_row->phone;
			$this->profile_picture = $user_row->profile_picture;
			$this->last_login = $user_row->last_login;
		}
	}

	public function __set($name, $value) {
		switch($name) {
			case 'user_id':
				if(!is_null($this->user_id)) {
					throw new Exception('Cannot update user\'s id');
				}
				break;
			case 'username':
				if(!is_null($this->username)) {
					throw new Exception('Cannot update username');
				}
				break;
			case 'fullname':
				if(!is_null($this->fullname)) {
					throw new Exception('Cannot update name');
				}
				break;
			case 'dob':
				if(!is_null($this->dob)) {
					throw new Exception('Cannot update dob');
				}
				break;
			case 'sex':
				if(!is_null($this->sex)) {
					throw new Exception('Cannot update sex');
				}
				break;
			case 'address':
				if(!is_null($this->address)) {
					throw new Exception('Cannot update address');
				}
				break;
			case 'email':
				if(!is_null($this->email)) {
					throw new Exception('Cannot update email');
				}
				break;
			case 'phone':
				if(!is_null($this->phone)) {
					throw new Exception('Cannot update phone');
				}
				break;
			case 'profile_picture':
				if(!is_null($this->profile_picture)) {
					throw new Exception('Cannot update profile picture');
				}
				break;
			case 'last_login':
				if(!is_null($this->last_login)) {
					throw new Exception('Cannot update last login');
				}
				break;
		}
		$this->$name = $value;
	}

	public function __get($name) {
		return $this->$name;
	}
}
